/**
 * 保证在没有引用coos.js的时候能够使用该组件用的的接口函数
 */
if (!coos) {var coos = function(){};}
if(!coos.$obj)
{
	coos.$obj = function(el)
	{
		var obj = el;
		if(typeof(el) == "string")
			obj = document.getElementById(el);
		return obj;
	};
}
if(!coos.style)
{
	coos.style = {
		add : function(content)
		{
			var style = null;
		    if(document.all)
		    {
		        style = document.createStyleSheet();
		        style.cssText = content;
		    }
		    else
		    {
		        style = document.createElement("style");
		        style.type = "text/css";
		        //style.innerHTML = content;//Safari、Chrome 下innerHTML只读
		        style.textContent = content;
		        try
		        {
		    		document.getElementsByTagName("head")[0].appendChild(style);
		    	}
		    	catch(e){}
		    }
		}
	};
}

/**
 * 图片幻灯片效果
 * @param element 现实幻灯片的DOM元素，一般为div
 * @param image 默认图片
 * @param srcs 图片路径数组
 * @param urls 图片链接url
 * @param descs 图片描述数组，对应容器的id必须为element的id加上_desc
 * @param time 滑动时间(秒)默认3秒
 * @example
<script type="text/javascript">
function initSlideImage()
{
	var srcs = [];
	srcs[0] = "../../images/secret.gif";
	srcs[1] = "../../images/real.gif";
	srcs[2] = "../../images/specialized.gif";
	var descs = [];
	descs[0] = "我的账户栏目采用五星安全认证，只有您本人才可登录浏览";
	descs[1] = "您所浏览到的笔记内容皆为持有或最近买卖过该证券的客户所写";
	descs[2] = "您的身边有一个充满理想的分析师团队，为您提供最贴心专业的服务";
	var time = 3000;
	coos.slide.init("slide_div","slide_img",srcs,descs,time);
	document.getElementById("slide_div_desc").innerHTML = descs[0];
}
onloadEvent(initSlideImage);
</script>
<div id="slide_div" style="width:340px;height:210px;">
	<img id="slide_img" src="../../images/secret.gif" width="339" height="210"  alt=""/>
</div>
<div id="slide_div_desc" style="width:335px;height:30px;margin-top:5px;margin-left:5px;"></div>

 * 
  */
coos.slide = function(element,image,srcs,descs,time)
{
	if(!element)return;
	this.element = coos.$obj(element);
	this.image = coos.$obj(image);
	this.srcs = srcs || [];
	this.descs = descs || [];
	this.descid = this.element.id + "_desc";
	this.descEl = coos.$obj(this.descid);
	this.time = time || 3*1000;
	this.timeout = null;
	this.index = 1;
	this.len = this.srcs.length;
	this.numbers = [];
	var numberStyle = "." + this.element.id + "_number{" + "float:left;background-color:#09C;color:#FFF;text-align: center;cursor:pointer;padding:0 2px !important;padding:0 6px;margin-right:1px;width:15px;height:13px;line-height:13px;border:1px #ccc solid;font-size:12px;}";
	coos.style.add(numberStyle);
	this.numberClass = this.element.id + "_number";
	this.numberscss = "position:relative;width:" + this.len*22 + "px;margin-left:" + (parseInt(this.element.style.width)-this.len*22) + "px;height:15px;text-align: right;vertical-align: bottom;margin-top:-16px !important;margin-top:-20px;z-index:1000;";

	this.element.onmouseover = function()
	{
		coos.slide.obj.stop();
	};
	this.element.onmouseout = function()
	{
		coos.slide.obj.start();
	};
	this.show = function()
	{
		coos.slide.obj.image.src =  coos.slide.obj.srcs[coos.slide.obj.index];
		coos.slide.obj.shownumber(coos.slide.obj.index);
		coos.slide.obj.descEl.innerHTML = coos.slide.obj.descs[coos.slide.obj.index];
		if(document.all)
		{
			coos.slide.obj.image.style.filter="progid:DXImageTransform.Microsoft.Fade(duration=2,overlap=0.4)";
			coos.slide.obj.image.filters[0].Apply();	
			coos.slide.obj.image.filters[0].Play();
		}
		if(coos.slide.obj.index+1 < coos.slide.obj.len)
		{
			coos.slide.obj.index +=1;
		}
		else
		{
			coos.slide.obj.index = 0;
		}
	};
	this.start = function()
	{
		coos.slide.obj.timeout = setInterval("coos.slide.obj.show()",coos.slide.obj.time);
	};
	this.stop = function()
	{
		clearTimeout(coos.slide.obj.timeout);
	};
	this.number = function()
	{
		var numbersdiv = document.createElement("div");
		numbersdiv.style.cssText = coos.slide.obj.numberscss;
		coos.slide.obj.element.appendChild(numbersdiv);
		for(var i = 0; i < coos.slide.obj.len; i++)
		{
			var numdiv = document.createElement("div");
			numdiv.id = coos.slide.obj.element.id + "_num_" + i;
			numdiv.innerHTML = i+1;
			if(i == 0)
			{
				numdiv.className = coos.slide.obj.numberClass;
				numdiv.style.backgroundColor = "red";
			}
			else
			{
				numdiv.className = coos.slide.obj.numberClass;
			}
			
			numdiv.onclick = function()
			{
				coos.slide.obj.stop();
				var index = this.id.split("_num_")[1];
				coos.slide.obj.index = parseInt(index);
				coos.slide.obj.show();
			};
			numbersdiv.appendChild(numdiv);
			coos.slide.obj.numbers[i] = numdiv;
		};
	};
	this.shownumber = function(index)
	{
		for(var i = 0; i < coos.slide.obj.len; i++)
		{
			if(i == index) continue;
			coos.slide.obj.numbers[i].style.backgroundColor = "#09C";
		}
		if(coos.slide.obj.numbers[index])
		{
			coos.slide.obj.numbers[index].style.backgroundColor = "red";
		}
	};
};
coos.slide.init = function(element,image,srcs,time)
{
	coos.slide.obj = new coos.slide(element,image,srcs,time);
	coos.slide.obj.number();
	coos.slide.obj.start();
};
